package com.barbarosso.utils.loader.types {
	import flash.events.Event;	
	import flash.errors.IllegalOperationError;
	import flash.events.EventDispatcher;		

	/**
	 * @author barbarosso
	 */
	public class AbstractAsset extends EventDispatcher {
		
		protected var _id 			: String;
		protected var _source		: String;
		protected var _fileSize 	: int;
		
		protected var _isLoaded 		: Boolean = false;		

		public function AbstractAsset(p_id : String , p_source : String , p_fileSize : int = 0) {
			super(null);
			_id = p_id;
			_source = p_source;
			_fileSize = p_fileSize;
		}

		/*
		 * protected methods ----------------------------------------------
		 */
		protected function isValidType( source : String ) : Boolean {
			throw IllegalOperationError("should be overriden by real AssetType => needs to check if type is correct " + source);
			return null;
		}
		
		protected function extractFileType(file:String):String {
			var extensionIndex:Number = file.lastIndexOf(".");
			if (extensionIndex == -1) {
				//No extension
				return "";
			} else {
				return file.substr(extensionIndex + 1,file.length).toLowerCase();
			}
		}

		/*
		 * public methods ----------------------------------------------
		 */	
		 public function load() : void {
		 	throw IllegalOperationError("should be overriden by real AssetType => start load of current asset");
		 }

		 public function cancel() : void {
		 	throw IllegalOperationError("should be overriden by real AssetType => cancels load of current asset");
		 }
		
		public function getAsset() : Object {
			throw IllegalOperationError("should be overriden by real AssetType => needs to check if type is correct ");
			return null;
		}
		
		/*
		 * eventhandling methods ----------------------------------------------
		 */
		 protected function isLoading( event : Event) : void {
		 	
		}
		
		/*
		 * setters and getters methods ----------------------------------------------
		 */ 
		public function get isLoaded (  ) : Boolean {
			return _isLoaded  ;
		}
		
		public function set id ( value : String ) : void {
			_id = value ;
		}
		public function get id (  ) : String {
			return _id  ;
		}
		
	}
}
